<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>
<?php if (!Mage::helper('core/cookie')->isUserNotAllowSaveCookie()): ?>
    <?php
    /** @var Enterprise_GoogleAnalyticsUniversal_Block_Ga $this */
    $accountType = Mage::getStoreConfig(Enterprise_GoogleAnalyticsUniversal_Helper_Data::XML_PATH_TYPE);
    $gtmAccountId = Mage::getStoreConfig(Enterprise_GoogleAnalyticsUniversal_Helper_Data::XML_PATH_CONTAINER_ID);
    $gapAccountId = Mage::getStoreConfig(Enterprise_GoogleAnalyticsUniversal_Helper_Data::XML_PATH_ACCOUNT) ;
    ?>
<?php switch ($accountType): ?>
<?php case Enterprise_GoogleAnalyticsUniversal_Helper_Data::TYPE_TAG_MANAGER: ?>
    <?php if (!empty($gtmAccountId)): ?>
        <!-- GOOGLE TAG MANAGER -->
        <noscript>
            <iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $gtmAccountId ?>" height="0" width="0" style="display:none;visibility:hidden"></iframe>
        </noscript>
        <script type="text/javascript">
            //<![CDATA[
            (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});
                var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;
                j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
            })(window,document,'script','dataLayer','<?php echo $gtmAccountId ?>');

            var dlCurrencyCode = '<?php echo $this->getStoreCurrencyCode() ?>';
            <?php echo $this->getOrdersData() ?>
            //]]>
        </script>
        <!-- END GOOGLE TAG MANAGER -->
    <?php endif; ?>
    <?php break; ?>
<?php case Enterprise_GoogleAnalyticsUniversal_Helper_Data::TYPE_UNIVERSAL: ?>
    <?php if (!empty($gapAccountId)): ?>
    <!-- BEGIN GOOGLE UNIVERSAL ANALYTICS CODE -->
    <script type="text/javascript">
        //<![CDATA[
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

        <?php echo $this->_getPageTrackingCode($gapAccountId) ?>
        <?php echo $this->_getOrdersTrackingCode() ?>

        //]]>
    </script>
    <!-- END GOOGLE UNIVERSAL ANALYTICS CODE -->
    <?php endif; ?>
    <?php break; ?>
<?php case Enterprise_GoogleAnalyticsUniversal_Helper_Data::TYPE_ANALYTICS: ?>
    <!-- BEGIN GOOGLE ANALYTICS CODE -->
    <script type="text/javascript">
        //<![CDATA[
        var _gaq = _gaq || [];
        <?php echo $this->_getPageTrackingCode($gapAccountId) ?>
        <?php echo $this->_getOrdersTrackingCode() ?>

        (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();
        //]]>
    </script>
    <!-- END GOOGLE ANALYTICS CODE -->
    <?php break; ?>
<?php endswitch; ?>

<?php endif; ?>
